home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / dnsconf / dnsrecs.c < prev    next >
C/C++ Source or Header  |  1996-07-27  |  3KB  |  131 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "../misc/misc.h"
  4. #include "dnsconf.h"
  5. #include "internal.h"
  6. #include "../paths.h"
  7. #include "dnsconf.m"
  8.  
  9. static DNSCONF_HELP_FILE help_dnsedit ("edit");
  10.  
  11. /*
  12.     Edit a host or sub-domain information.
  13.      -A and PTR record) globally.
  14.      -NS record
  15.      -CNAME
  16.      -MX
  17.  
  18.     All in a single dialog
  19. */
  20. PUBLIC void DNS::editrecs(const char *name)
  21. {
  22.     FQHOST fq (name);
  23.     SSTRING full;
  24.     fq.formatfull(full);
  25.     PRIMARY *pri = primarys.getitem(fq,NULL);
  26.     if (pri == NULL){
  27.         xconf_error (MSG_U(E_HOSTNODOM
  28.             ,"Host %s is not part of any domain\n"
  29.              "managed by this DNS"),full.get());
  30.     }else{
  31.         IPMAPS maps;
  32.         IP_ADDRS adrs;
  33.         primarys.getalladr (adrs);
  34.         maps.setuse (adrs);
  35.         DIALOG dia;
  36.         dia.newf_str (MSG_U(F_HOST_DOM,"host or sub-domain"),full);
  37.         SSTRINGS tbns;
  38.         pri->getns(full,tbns);
  39.         while (tbns.getnb()<3) tbns.add (new SSTRING);
  40.         SSTRINGS tbmx;
  41.         pri->getmx(full,tbmx);
  42.         while (tbmx.getnb()<3) tbmx.add (new SSTRING);
  43.         IP_ADDRS tba;
  44.         pri->geta(full,tba);
  45.         while (tba.getnb()<4) tba.add (new IP_ADDR);
  46.         SSTRING cname;
  47.         pri->getcname (full,cname);
  48.         dia.newf_str (MSG_U(F_NICKNAME,"is a nick name for"),cname);
  49.         int i;
  50.         dia.newf_title ("",MSG_U(F_IPADRS,"IP addresses"));
  51.         for (i=0; i<tba.getnb(); i++){
  52.             FIELD_COMBO *comb = dia.newf_combo ("",*(tba.getitem(i)));
  53.             maps.setcombo(comb);
  54.         }
  55.         dia.newf_title ("",MSG_U(F_DNSADV,"DNS advertising"));
  56.         for (i=0; i<tbns.getnb(); i++){
  57.             dia.newf_str ("",*(tbns.getitem(i)));
  58.         }
  59.         dia.newf_title ("",MSG_U(F_EMAILADV,"EMAIL advertising"));
  60.         for (i=0; i<tbmx.getnb(); i++){
  61.             dia.newf_str ("",*(tbmx.getitem(i)));
  62.         }
  63.         int nofield = 0;
  64.         while (1){
  65.             MENU_STATUS code = dia.edit(MSG_U(T_HOSTINFO,"Host information")
  66.                 ,MSG_U(I_HOSTINFO,"Enter a host name + domain\n"
  67.                  "and its IP numbers (at least one)\n"
  68.                  "and all DNS's table will be updated\n")
  69.                 ,help_dnsedit.getpath()
  70.                 ,nofield
  71.                 ,MENUBUT_ACCEPT|MENUBUT_CANCEL|MENUBUT_DEL);
  72.             if (code == MENU_CANCEL){
  73.                 break;
  74.             }else{
  75.                 if (code == MENU_DEL){
  76.                     if (xconf_yesno(MSG_U(Q_CONFIRM,"Please confirm")
  77.                         ,MSG_U(I_CONFIRM,"Are you sure you want to\n"
  78.                          "delete this entry")
  79.                         ,help_dnsedit)
  80.                         == MENU_YES){
  81.                         tbns.delall();
  82.                         tbmx.delall();
  83.                         tba.delall();
  84.                         cname.setfrom ("");
  85.                     }else{
  86.                         continue;
  87.                     }
  88.                 }
  89.                 const char *tbip[4];
  90.                 int nb = 0;
  91.                 for (i=0; i<tba.getnb(); i++){
  92.                     SSTRING *a = tba.getitem(i);
  93.                     if (!a->is_empty()){
  94.                         tbip[nb++] = a->get();
  95.                     }
  96.                 }
  97.                 set (full.get(),tbip,nb);
  98.                 setns (full,tbns);
  99.                 setmx (full,tbmx);
  100.                 setcname (full,cname);
  101.                 write();
  102.                 break;
  103.             }
  104.         }
  105.     }
  106. }
  107.  
  108. /*
  109.     Edit the host information (A, PTR, NS and MX records) globally.
  110. */
  111. PUBLIC void DNS::editrecs()
  112. {
  113.     /* #Specification: dnsconf / host editition
  114.         The user is prompted to enter a host or domain name.
  115.         The system query all configured information about
  116.         this host. All this is displayed in a form. The user
  117.         can correct and add information.
  118.     */
  119.     char name[MAX_LEN+1];
  120.     while(xconf_inputbox(
  121.         MSG_U(Q_HOSTNAME,"Host or domain specification")
  122.         ,MSG_U(I_HOSTNAME,"Enter the name of a host or the name of a\n"
  123.          "sub-domain.")
  124.         ,help_dnsedit
  125.         ,name)==MENU_ACCEPT){
  126.         if (name[0] != '\0') editrecs (name);
  127.     }
  128. }
  129.  
  130.  
  131.